<template>
    <view>
		<view>
			<text>{{mess}}</text>
		</view>
		<view>
			<text>用户名</text>
			<input type="text" v-model="user.username" />
		</view>
        <view>
			<text>密码</text>
			<input password v-model="user.password" />
		</view>
		
		<button v-on:click="login">登陆</button>
		<button v-on:click="logup">注册</button>
    </view>
</template>
<script>
	import common from '../../common/common.js';
	export default {
	   data(){
		   return {
			   user: {
				   username: 'hhq',
				   password: 'hhq'
			   },
			   mess: "",
		   }
	   },
	   onShow(){
		   console.log('onShow');
	   },
	   methods:{
		   logup(){
			   uni.navigateTo({
			   	url:"../logup/logup"
			   })
		   },
		   login(){
			   this.myReq({
				   url: 'log_in',
				   method: "POST",
				   data: JSON.stringify({
					   username: this.user.username,
					   password: common.getRsaCode(this.user.password)
				   })
			   }).then((res)=>{
				   console.log(this.user.username);
				   if(res.data.userID){
						uni.setStorageSync('userID', res.data.userID)
						this.userID.id = res.data.userID
						console.log('登陆成功:'+this.userID.id);
						uni.switchTab({
							url: "/pages/my/my"
						})
				   }
				   else{
						console.log('登陆失败');
						this.mess='登陆失败，用户名或者密码错误，或者被管理员封号'
				   }
			   })
		   }
	   }
	    
	}

	
</script>

<style>
input{
		background-color: #F8F8F8;
		font-size: 60rpx;
		border:2rpx solid;
		border-radius: 25rpx;
	}
</style>
